package com.neusoft.neuiotms.dcom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.OperationGroupDTO;
import com.neusoft.neuiotms.dcom.service.OperationGroupService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "运维组管理")
@RestController
@RequestMapping(value = "/api/w/operationGroups")
public class OperationGroupController {

    @Autowired
    private OperationGroupService operationGroupService;

    @ApiOperation("查询所有运维组")
    @GetMapping
    public ResultListDTO<OperationGroupDTO> index(final Searchable searchable) {
        return ResultListDTO.success(this.operationGroupService.index(searchable));
    }

    @ApiOperation("分页查询所有运维组")
    @GetMapping("/p")
    public PageResultDTO<OperationGroupDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.operationGroupService.page(searchable, pageable));
    }

    @ApiOperation("创建运维组")
    @PostMapping("")
    public ResultDTO<OperationGroupDTO> create(@RequestBody final OperationGroupDTO dto) {
        return ResultDTO.success(this.operationGroupService.create(dto));
    }

    @ApiOperation(value = "修改运维组")
    @PutMapping("/{id}")
    public ResultDTO<OperationGroupDTO> update(@PathVariable final Long id, @RequestBody final OperationGroupDTO dto) {
        return ResultDTO.success(this.operationGroupService.update(id, dto));
    }

    @ApiOperation("运维组详情")
    @GetMapping("/{id}")
    public ResultDTO<OperationGroupDTO> details(@PathVariable final String id) {
        return ResultDTO.success(this.operationGroupService.detail(id));
    }

    @ApiOperation("删除运维组")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.operationGroupService.delete(id);
        return ResultDTO.success();
    }
}
